<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.lgx.right.entity.User"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	User onlineUser = (User)request.getAttribute("onlineUser");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>修改个人资料</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<jsp:include page="/page/jsp/member/head.jsp" />
	<script type="text/javascript">
		//保存信息
		function save(){
			
			$('#saveBtn').attr('disabled','disabled');
			var sex = escape(escape($('#sex').val()));                   	//获取sex值
			var truename = escape(escape($('#truename').val()));            //获取truename 
			var nickname = escape(escape($('#nickname').val()));         	//获取username值
			var email = escape(escape($('#email').val()));               	//获取truename值
			
			
			var url = path +"/member/update.htm?userId="+${onlineUser.getId()}+"&truename="+truename+"&sex="+sex+"&email="+email+"&nickname="+nickname;
				//执行ajax操作
				$.ajax({
					  url:url,
					  success: function(data) {
						  if(data == "1"){
							  alertBox("修改成功！");
						   }else{
							   alertBox("操作失败！");
						   } 
					  }
				});
		}
		
		
		//中文验证,不能为空
		function chs(input){
			if(input.value==''){
				alertBox("请输入真实姓名！");
				return false;
			}else if(/^[\u0391-\uFFE5]+$/.test(input.value)){
				return true;
			}
			alertBox("只能输入中文！");
			input.value='';
			return false;
		}
		
		//邮箱验证，可以为空
		function isEmail(input){
			if(/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(input.value)){
				return true;
			}
			alertBox("请输入正确的邮箱地址！");
			input.value='';
			return false;
		}
		
	</script>
  </head>
  
  <body>
   <div class="right">
	<h1><b>修改个人资料</b><span><img src="<%=basePath%>images/right_h1bg2.jpg" width="3" height="29" /></span></h1>
	<div class="ri_main">
	<form id="form" method="post">
		<table width="100%" border="0" cellspacing="1" cellpadding="8" style="background:#d9d9d9;">
		  <tr>
			<td width="15%" align="center" bgcolor="#FFFFFF">会员卡号</td>
		    <td width="40%" bgcolor="#FFFFFF" align="left" colspan="3"><label for="textfield"></label>
		    	<label id="cardid" name="cardid" style="width:200px;">${onlineUser != null?onlineUser.card.id:'' }</label>
		    </td>
		  </tr>
		  <tr>
		  	<td width="15%" align="center" bgcolor="#FFFFFF">登录名</td>
		    <td width="40%" bgcolor="#FFFFFF" align="left"><label for="textfield"></label>
		      <lable>${onlineUser != null?onlineUser.username:'' }</lable>
		    </td>
		    <td align="center" bgcolor="#FFFFFF">手机号码</td>
		    <td bgcolor="#FFFFFF" colspan="3" align="left">
		    	<lable>${onlineUser != null?onlineUser.mobile:'' }</lable>
		    </td>
		  </tr>
		   <tr>
			<td width="15%" align="center" bgcolor="#FFFFFF">真实姓名</td>
		    <td width="40%" bgcolor="#FFFFFF" align="left"><label for="textfield"></label>
		      <input validType="chs" id="truename" name="truename" onblur="return chs(this)" class="easyui-validatebox" required="true" style="width:200px;" value="${onlineUser != null?onlineUser.truename:'' }" />
		      [输入汉字]
		    </td>
		    <td width="15%" align="center" bgcolor="#FFFFFF">性&nbsp;&nbsp;&nbsp;别</td>
		    <td width="30%" align="left" bgcolor="#FFFFFF">
		    	<select id="sex" name="sex" style="width: 100px;">
		    		<c:forEach var="dict" items="${sexTypes}">
		    			<c:choose>
		    				<c:when test="${onlineUser != null && dict.code == onlineUser.sex}">
		    					<option value="${dict.code }" selected="selected"> ${dict.name } </option>
		    				</c:when>
		    				<c:otherwise>
		    					<option value="${dict.code }"> ${dict.name } </option>
		    				</c:otherwise>
		    			</c:choose>
		    		</c:forEach>
		    	</select>
		    </td>
		    
		  </tr>
		  <tr>
			<td width="15%" align="center" bgcolor="#FFFFFF">昵称</td>
		    <td width="40%" bgcolor="#FFFFFF" align="left" colspan="3"><label for="textfield"></label><!-- ${onlineUser.nickname} -->
		      <input id="nickname" name="nickname" class="easyui-validatebox" required="true" style="width:200px;" value="${onlineUser != null?onlineUser.nickname:'' }" />
		    </td>
		  </tr>
		  <tr>
		    <td align="center" bgcolor="#FFFFFF">邮&nbsp;&nbsp;&nbsp;箱</td>
		    <td bgcolor="#FFFFFF" colspan="3" align="left">
		    	<input validType="email" id="email" name="email" onblur="return isEmail(this)" class="easyui-validatebox" required="true" style="width:200px;" value="${onlineUser != null?onlineUser.email:'' }" />
		    </td>
		  </tr>
		  <tr>
		      <td bgcolor="#FFFFFF" colspan="4" style="text-align: center;">
		      	<input type="button" name="button" id="button" onclick="save()" value="保  存" />
		      </td>
		  </tr>
		</table>
	</form>
	</div>
	</div>
  </body>
</html>
